<template>
	<view class="container">
		
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			}
		},
		onLoad(o) {
			if (JSON.stringify(o) !== '{}' && o.scene !== undefined) {
				//扫码进来的
				let scene = decodeURIComponent(o.scene);
				console.log('scene', scene);
				this.admin_id = scene
			}

			if (!uni.getStorageSync('token')) {
				this.wxlogin()
			} else {
				this.getSystemConfig()
			}
			//加密
			function encryptUrl(url) {
				let encryptedUrl = "";
				for (let i = 0; i < url.length; i++) {
					encryptedUrl += String.fromCharCode(url.charCodeAt(i) + i);
				}
				return encryptedUrl;
			}

			let originalUrl = "https://www.baidui.com";
			let encryptedUrl = encryptUrl(originalUrl);
			//解密
			function decryptUrl(encryptedUrl) {
				let decryptedUrl = "";
				for (let i = 0; i < encryptedUrl.length; i++) {
					decryptedUrl += String.fromCharCode(encryptedUrl.charCodeAt(i) - i);
				}
				return decryptedUrl;
			}
			let decryptedUrl = decryptUrl(encryptedUrl);
			console.log(encryptedUrl, decryptedUrl);

		},
		methods: {
			
			wxlogin() {
				uni.login({
					provider: 'weixin',
					success: (data) => {
						this.code = data.code
						this.$http.post('/api/user/wxLogin', {
							code: data.code,
							admin_id: this.admin_id
						}).then(res2 => {
							if (res2.code == 1) {
								uni.setStorageSync('token', res2.data.userinfo.token)
								uni.setStorageSync('userId', res2.data.userinfo.user_id)
								let loginTime = new Date().getTime()
								uni.setStorageSync('loginTime', loginTime)
								this.getSystemConfig()
								uni.showToast({
									title: '登录成功',
									icon: "none",
									duration: 1500
								});

							} else {
								uni.showToast({
									title: res2.msg,
									icon: "none"
								});
							}
						}).catch(err2 => {
							console.log('表单错误信息：', err2);
						})
					}
				});
			},
		}
	}
</script>

<style lang="less" scoped>
	
</style>